﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Advanced.aspx.cs" Inherits="ShoppingApp.Advanced" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="Addr_Id" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="Addr_Id" HeaderText="Addr_Id" InsertVisible="False" 
                ReadOnly="True" SortExpression="Addr_Id" />
            <asp:TemplateField HeaderText="City" SortExpression="City">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource2" DataTextField="City" DataValueField="City" 
                        SelectedValue='<%# Bind("City") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("City") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Street" HeaderText="Street" 
                SortExpression="Street" />
        </Columns>
    </asp:GridView>
    <asp:DropDownList ID="DropDownList2" AutoPostBack="true" ForeColor="White" BackColor="Blue" runat="server">
        <asp:ListItem Value="sampleTheme">sampleTheme</asp:ListItem>
        <asp:ListItem Value="No Theme">No Theme</asp:ListItem>
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
        DeleteCommand="DELETE FROM [Addresses] WHERE [Addr_Id] = @Addr_Id" 
        InsertCommand="INSERT INTO [Addresses] ([City], [Street]) VALUES (@City, @Street)" 
        SelectCommand="SELECT * FROM [Addresses]" 
        UpdateCommand="UPDATE [Addresses] SET [City] = @City, [Street] = @Street WHERE [Addr_Id] = @Addr_Id">
        <DeleteParameters>
            <asp:Parameter Name="Addr_Id" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Street" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Street" Type="String" />
            <asp:Parameter Name="Addr_Id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
        SelectCommand="SELECT DISTINCT [City] FROM [Addresses]"></asp:SqlDataSource>
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "City") %>
        </ItemTemplate>
        <HeaderTemplate>
            <br />
            City
            <br />
        </HeaderTemplate>
        <SeparatorTemplate>
            <br />
            <hr />
        </SeparatorTemplate>
    </asp:Repeater>
</asp:Content>
